const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: true,
    showphone: true,
    showaddress: true,
    date: "2016-09-01",
    // person: {
    // name:'',
    // phone:'',
    // // sex:'',
    // address:'',
    // CustomerId:'',
    // },
    lsvalue: '',
    person: {

    },
    userNickName: '师为荣',
    sex: ["男", "女"],
    sexIndex: 0,
  },
  name: function(e) {
    this.setData({
      show: !this.data.show
    })
  },
  phone: function() {
    this.setData({
      showphone: !this.data.showphone
    })
  },

  address: function() {
    this.setData({
      showaddress: !this.data.showaddress
    })
  },
  person_close: function(e) {
    var that = this
      var animation = wx.createAnimation({
        duration: 1000,
        timingFunction: 'ease'
      });
      animation.translate(0, 0).step()
      if (e.target.id) {
        this.setData({
          show: true,
          ani: animation.export(),
           lsvalue: ''
        })
      }
  },
  phone_close: function() {
    this.setData({
      showphone: !this.data.showphone
    })
  },
  address_close: function(e) {
    this.setData({
      showaddress: !this.data.showaddress,
      lsvalue: ''
    })
  },

  //输入事件
  // changeName: function(e) {
  //   this.setData({
  //     nameb: e.detail.value
  //   })
  // },
  changeText: function(e) { 
    let name = e.currentTarget.dataset.name;
    let nameMap = {}
    nameMap[name] = e.detail && e.detail.value
    this.setData(nameMap)
  },

  // changePhone: function(e) {
  //   this.setData({
  //     phoneb: e.detail.value
  //   })
  // },



  person_true: function(e) {
    var that = this
    if (that.data.lsvalue) {
      let name = e.currentTarget.dataset.name;
      let nameMap = that.data.person
      // console.log(nameMap[name])
      nameMap[name] = that.data.lsvalue
      that.setData(nameMap)
      // console.log(that.data.person)
      //   //调用修改接口
      app.req({
        url: 'User/CustomerWchat',
        method: "POST",
        data: that.data.person,
        success: function(res) {
          if (res.data.Code == true) {
            wx.showToast({
              title: '修改成功',
              icon: 'success'
            })
            // that.hquser();
            that.setData({
              showphone: true,
              show: true,
              showaddress: true,
              lsvalue: ''
            })
            that.onLoad()
          }
        }
      })
    } else {
      wx.showToast({
        title: '修改内容不能为空/不变',
        icon: 'none'
      })
    }

  },

  //获取用户信息
  hquser: function() {
    var that = this;
    app.req({
      url: 'User/CustomerWchatDetail',
      success: function(res) {
        that.setData({
          person: res.data.Result
        })


      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.hquser();
  },

  // // 性别
  bindCountryChange: function(e) {
    var that = this
    var obj = this.data.person
    if (e.detail.value == 0) {
      obj.Sex = true
    } else if (e.detail.value == 1) {
      obj.Sex = false
    }
    this.setData({
      person: obj
    })
    app.req({
      url: 'User/CustomerWchat',
      method: "POST",
      data: that.data.person,
      success: function(res) {
        if (res.data.Code == true) {
          wx.showToast({
            title: '修改成功',
            icon: 'success'
          })
          // that.hquser();
          that.setData({
            showphone: true,
            show: true,
            showaddress: true,
          })
          that.onLoad()
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})